package 枚举与尺聚法;

import java.util.Scanner;
import java.util.Stack;

public class 座次问题 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String[] name = new String[n];
        int[] isFlag = new int[n];
        for (int i = 0; i < n; i++) {
            name[i] = scanner.next();
        }
        Stack<String> stack = new Stack();
        dfs(n, isFlag, name, stack);

    }

    private static void dfs(int n, int[] isFlag, String[] name, Stack<String> stack) {
        if (stack.size() == n) {
            for (String s : stack) {
                System.out.print(s + " ");
            }
            System.out.println();
            return;
        }
        for (int i = 0; i < name.length; i++) {
            if (isFlag[i] != 1) {
                isFlag[i] = 1;
                stack.push(name[i]);
                dfs(n, isFlag, name, stack);
                isFlag[i] = 0;
                stack.pop();
            }
        }


    }
}
